package leetcode_动态规划._01斐波那契数列;

public class 信件错排 {
    public static void main(String[] args) {
        System.out.println(new 信件错排().method(3));
    }

    public int method(int n) {
        if (n == 0 || n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        int[] dp = new int[n + 1];
        dp[0] = dp[1] = 0;
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]);
        }
        return dp[n];
    }
}
